package com.avantis.common.repository;

import com.avantis.common.entity.User;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @ClassName UserRepository
 * @Description TODO
 * @Author kirago
 * @Date 2018/11/26 19:35
 * @Version 1.0
 **/
@Repository
@CacheConfig(cacheNames = "users")
public interface UserRepository extends JpaRepository<User,Integer>, JpaSpecificationExecutor {

    Optional<User> findById(Integer id);
	User findByUserName(String username);

	User findByEmail(String email);

	@Query(value = "select u.id, u.username , u.icon from quark_user u where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <=DATE(u.init_time) ORDER BY u.id DESC limit 12" ,nativeQuery = true)
	List<Object> findNewUser();

}